﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Home.Master" Inherits="System.Web.Mvc.ViewPage" %>

<%@ Import Namespace="WebHoiChoMuaBan.Models" %>
<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Helpers" %>
<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Utility" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleHolder" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="HeadHolder" runat="server">
   <%-- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>--%>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.3/jquery-ui.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#featured > ul").tabs({ fx: { opacity: "toggle"} }).tabs("rotate", 5000, true);
        });
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ListMenuHeader" runat="server">
    <div class="hoicho_group_product">
        <div class="hoicho_header_feature">
            <ul style="position:relative">
                <%
                    NewsProductHelper nProHelper = new NewsProductHelper();
                    string bold = "style='font-weight: bold'";
                    PageType curPage = (PageType)ViewData["CurrentPage"];
                    Category curCate = (Category)ViewData["CurrentCategory"];
                    int needSell = (int)ViewData["NeedSell"];
                    int provinceId = (int)ViewData["ProvinceId"];

                    List<Category> cate = (List<Category>)ViewData["Categories"];
                    int i;
                    foreach (Category c in cate)
                    {
                        bool isCurrent = curCate != null &&
                                            ((curCate.ParentCategory != null && c.CateId == curCate.ParentCategory.CateId) ||
                                             c.CateId == curCate.CateId);
                        Response.Write(string.Format("<li class='{0}'><a href='{1}?pid={2}&cid={3}&p={4}&need={5}&prvid={6}'>{7}</a>",
                                                    (isCurrent ? "selected_menu hover" : "hover"),
                                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                    curPage.PageId,
                                                    c.CateId,
                                                    1,
                                                    needSell,
                                                    provinceId,
                                                    c.CateName));
                        List<Category> subCate = nProHelper.getSubCate(c.CateId);
                        Response.Write("<div id='submenu'><span style='position: absolute; top: 30px;'><ul class='hidden' style='z-index:1000;'>");
                        foreach (Category sc in subCate)
                        {
                            Response.Write(string.Format("<li class='{0}'><a href='{1}?pid={2}&cid={3}&p={4}&need={5}&prvid={6}'>{7}</a></li>",
                                                           (""),
                                                           Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                           curPage.PageId,
                                                           sc.CateId,
                                                           1,
                                                           needSell,
                                                           provinceId,
                                                           sc.CateName));
                        }
                        Response.Write("</ul></span><div></li>");
                    }
                %>
            </ul>
            <%--     <%
                foreach (Category sc in cate)
                {
                    List<Category> subCate = nProHelper.getSubCate(sc.CateId);
                    Response.Write("<div>");
                    Response.Write(string.Format("<li class='{0}'><a href='{1}?pid={2}&cid={3}&p={4}&need={5}&prvid={6}'>{7}</a></li>",
                                                   ( string.Empty),
                                                   Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                   curPage.PageId,
                                                   sc.CateId,
                                                   1,
                                                   needSell,
                                                   provinceId,
                                                   sc.CateName));
                    Response.Write("</div>");
                }
                   %>--%>
        </div>
        <div class="hoicho_feature_content">
            <%--     <div class="private_breakpage_replycoment col_left reset_margin">
                <%
                    Response.Write(string.Format("<a {0} href='{2}?pid={3}&cid={4}&p={5}&need={6}&prvid={8}'>Cần bán</a> | <a {1} href='{2}?pid={3}&cid={4}&p={5}&need={7}&prvid={8}'>Cần mua</a>",
                                                    (needSell == NewsProductHelper.NEED_SELL ? bold : string.Empty),
                                                    (needSell == NewsProductHelper.NEED_BUY ? bold : string.Empty),
                                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                    curPage.PageId,
                                                    (curCate != null ? curCate.CateId : 0),
                                                    1,
                                                    NewsProductHelper.NEED_SELL,
                                                    NewsProductHelper.NEED_BUY,
                                                    provinceId));
                %>
            </div>--%>
            <%--       <div class="hoicho_select_province col_right">
                <span class="hoicho_margin_right">
                    <%
                        StringBuilder provLinks = new StringBuilder();
                        provLinks.Append("<a {0} href='{4}?pid={5}&cid={6}&p={7}&need={8}&prvid=2'>Hà Nội</a> | ");
                        provLinks.Append("<a {1} href='{4}?pid={5}&cid={6}&p={7}&need={8}&prvid=6'>Hải Phòng</a> | ");
                        provLinks.Append("<a {2} href='{4}?pid={5}&cid={6}&p={7}&need={8}&prvid=3'>Hồ Chí Minh</a> | ");
                        provLinks.Append("<a {3} href='{4}?pid={5}&cid={6}&p={7}&need={8}&prvid=5'>Đà Nẵng</a> |");
                        Response.Write(string.Format(provLinks.ToString(),
                                                (provinceId == 2 ? bold : string.Empty), // {0}
                                                (provinceId == 6 ? bold : string.Empty), // {1}
                                                (provinceId == 3 ? bold : string.Empty), // {2}
                                                (provinceId == 5 ? bold : string.Empty), // {3}
                                                Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                curPage.PageId,
                                                (curCate != null ? curCate.CateId : 0),
                                                1,
                                                needSell // buy or sell
                                                ));
                    %>
                </span><span>
                    <select id="cbbProvince" class="hoicho_input_select_province">
                        <%
                            string selected = "selected='selected'";
                            List<Province> provinces = (List<Province>)ViewData["Provinces"];
                            foreach (Province pr in provinces)
                            {
                                Response.Write(string.Format("<option value='{0}' {2}>{1}</option>",
                                                            pr.ProvId,
                                                            pr.ProvName,
                                                            (provinceId == pr.ProvId ? selected : string.Empty)
                                                            ));
                            }
                        %>
                    </select>
                    <script type="text/javascript">
                            jQuery("#cbbProvince").change(function () {
                                location.href=<%=string.Format("'{0}?pid={1}&cid={2}&p={3}&need={4}'",
                                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                    curPage.PageId,
                                                    (curCate != null ? curCate.CateId : 0),
                                                    1,
                                                    needSell // buy or sell
                                                    ) %> + '&prvid=' + jQuery(this).val();
                            });
                    </script>
                </span>
            </div>--%>
        </div>
        <%
            //int j = 1;
            //foreach (Category c in cate)
            {
                //Response.Write(string.Format("<div id='cate_{1}' class='hoicho_group_listmenu_fation page_{2}' {0}>", (j>1 ? "style='display:none'" : string.Empty), c.CateId, c.PageId));
                Response.Write("<div>");
                //j++;

                if (curCate != null)
                {
                    List<CategoryHelper.SubCategory> subcategories = null;
                    if (curCate.SubCategories != null && curCate.SubCategories.Count > 0)
                    {
                        //Số dòng mỗi cột
                        subcategories = (from sub in curCate.SubCategories
                                         select new CategoryHelper.SubCategory
                                         {
                                             id = sub.CateId,
                                             name = sub.CateName
                                         }).ToList();
                    }
                    else if (curCate.ParentCategory != null)
                    {
                        subcategories = (from sub in curCate.ParentCategory.SubCategories
                                         select new CategoryHelper.SubCategory
                                         {
                                             id = sub.CateId,
                                             name = sub.CateName
                                         }).ToList();
                    }

                    if (subcategories != null)
                    {
                        int perRow = (int)Math.Ceiling((double)subcategories.Count / 4);

                        //4 cột subcategories
                        for (i = 0; i < 4; i++)
                        {
                            var subCate = (from sub in subcategories select sub).Skip(perRow * i).Take(perRow);
                            if (subCate != null)
                            {
                                Response.Write("<div class='private_menu_list_product'><ul>");
                                foreach (var s in subCate)
                                    Response.Write(string.Format("<li><a href='{0}?pid={1}&cid={2}&p={3}' style='font-weight: {4}'>{5}</a></li>",
                                                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                                    curPage.PageId,
                                                                    s.id,
                                                                    1,
                                                                    ((curCate != null && curCate.CateId == s.id) ? "bold" : "normal"),
                                                                    s.name));
                                Response.Write("</ul></div>");
                            }
                        }
                    }
                }
                Response.Write("</div>");
            }
        %>
    </div>
    <script type="text/javascript">
        $(".hoicho_group_product li.hover").mouseover(function () {
            $this = $(this).find("ul.hidden");
            $this.removeClass("hidden");
        });
        $(".hoicho_group_product li.hover").mouseout(function () {
            $this = $(this).find("ul");
            $this.addClass("hidden");
        });
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="MainContentHolder" runat="server">
    <%--Begin slider--%>
    <%NewsProductHelper pHelper = new NewsProductHelper();
      NewsProductThumbHelper productThumbHelper = new NewsProductThumbHelper();
      List<NewsProduct> news = pHelper.getSixLatestNews(int.Parse(Request.QueryString.Get("pid"))); int count = 0;%>
    <div id="featured">
        <ul class="ui-tabs-nav">
            <%foreach (NewsProduct hot in news)
              {
                  count++;
                  NewsProductThumb proThumb = productThumbHelper.getProductMainThumbById(hot.NProId);
                  if (proThumb != null)
                      Response.Write(string.Format("  <li class='ui-tabs-nav-item ui-tabs-selected' id='nav-fragment-{0}'><a href='#fragment-{1}'>  <img src='/../Content/Images/{2}' width='50px' height='50px' alt='' /> <span>{3}</span></a></li>", count, count, proThumb.NProThumbName, hot.NProTitle));
                  else
                      Response.Write(string.Format("  <li class='ui-tabs-nav-item ui-tabs-selected' id='nav-fragment-{0}'><a href='#fragment-{1}'>  <img src='/../Content/Images/{2}' width='50px' height='50px' alt='' /> <span>{3}</span></a></li>", count, count, "no-image.gif", hot.NProTitle));
              }
              count = 0;
            %>
        </ul>
        <!-- First Content -->
        <% foreach (NewsProduct hot in news)
           {
               NewsProductThumb proThumb = productThumbHelper.getProductMainThumbById(hot.NProId);
               count++;
               Response.Write(string.Format(" <div id='fragment-{0}' class='ui-tabs-panel' style=''>", count));
               if (proThumb != null)
                   Response.Write(string.Format("  <img src='/../Content/Images/{0}' width='500px' height='315px' alt='' />", proThumb.NProThumbName));
               else
                   Response.Write(string.Format("  <img src='/../Content/Images/{0}' width='500px' height='315px' alt='' />", "no-image.gif"));
               Response.Write(string.Format(" <div class='info'>"));
               Response.Write(string.Format(" <h2>"));
               Response.Write(string.Format("  <a href='{1}?prid={2}'>{0}</a></h2>", hot.NProTitle, Url.Action("Detail", "NewsProduct", new { productTitle = MiscUtil.EscapeString(hot.NProTitle) }), hot.NProId));
               Response.Write(string.Format(" <p>{0} <a href='{1}?prid={2}'>Xem Chi Tiết</a></p>", hot.NProIntro, Url.Action("Detail", "NewsProduct", new { productTitle = MiscUtil.EscapeString(hot.NProTitle) }), hot.NProId));
               Response.Write("    </div></div>");
           }
        %>
    </div>
    <%--end slider--%>
    <div class="hoicho_topbanner">
        <div class="hoicho_topbanner">
            <%
                AdvertHelper hAdvert = new AdvertHelper();
                Response.Write(hAdvert.showBanner(ViewData, 1));
            %>
        </div>
    </div>
    <%--begin content--%>
    <div class="left">
        <%if (Request.QueryString.Get("text") == null && Request.QueryString.Get("date") == null)
          {%>
        <%
            if (Request.QueryString.Get("cid").Equals("0"))
            {
                PageType curPage = (PageType)ViewData["CurrentPage"];
                Category curCate = (Category)ViewData["CurrentCategory"];
                int needSell = (int)ViewData["NeedSell"];
                int provinceId = (int)ViewData["ProvinceId"];
                List<Category> cate = (List<Category>)ViewData["Categories"];
                foreach (Category cat in cate)
                {
                    List<NewsProduct> pNews = pHelper.getFourLastestNewbyCategory(cat.CateId);
                    try
                    {
                        Response.Write(string.Format(" <div class='hoicho_group_product'><div class='hoicho_header_feature'><ul><li><p>{0}</p></li></ul></div>", cat.CateName));
                        Response.Write(string.Format("<div style='float:right'>"));
                        List<Category> subCate = pHelper.getSubCate(cat.CateId);
                        foreach (Category sc in subCate)
                        {
                            Response.Write(string.Format("<a style='padding-top:10px;padding-left:3px;padding-right:3px' href='{0}?pid={1}&cid={2}&p={3}' {4}>{5}</a> ",
                                     Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                    curPage.PageId,
                                    sc.CateId,
                                    1,
                                    string.Empty,
                                     sc.CateName));
                            
                        }
                        Response.Write(string.Format("</div></div>"));
                        NewsProductThumb proThumb = productThumbHelper.getProductMainThumbById(pNews[0].NProId);
                        Response.Write("<div style='float:left;width:28%'>");
                        Response.Write(string.Format("<a href='{0}?prid={1}' style='margin-bottom:3px;'>", Url.Action("Detail", "NewsProduct", new { productTitle = MiscUtil.EscapeString(pNews[0].NProTitle) }), pNews[0].NProId));
                        if (proThumb != null)
                            Response.Write(string.Format("<img width='140px' height='150px' src='/../Content/Images/{0}'/></div>", proThumb.NProThumbName));
                        else
                            Response.Write(string.Format("<img width='140px' height='150px' src='/../Content/Images/{0}'/></div>", "no-image.gif"));
                        Response.Write("</a>");
                        Response.Write("<div style='float:right;width:70%'>");
                        Response.Write(string.Format("<a class='hoitro_new_title' href='{0}?prid={1}'>", Url.Action("Detail", "NewsProduct", new { productTitle = MiscUtil.EscapeString(pNews[0].NProTitle) }), pNews[0].NProId));
                        Response.Write(string.Format("<p class='hoitro_new_title'>{0}</p>", pNews[0].NProTitle));
                        Response.Write(string.Format("<p class='' style='height:50px;color:#666;font-weight:lighter!important'>{0}</p></a>", pNews[0].NProIntro));
                        Response.Write("  <div class='' style='border-top:1px solid #bec9de; margin:5px;padding:2px;'></div>");
                    }
                    catch (Exception)
                    {
                    }

                    try
                    {
                        Response.Write(string.Format("<div class='hoitro_new_title_relate'> <a href='{0}?prid={1}'> {2}</a></div>", Url.Action("Detail", "NewsProduct", new { productTitle = MiscUtil.EscapeString(pNews[1].NProTitle) }), pNews[1].NProId, pNews[1].NProTitle));
                    }

                    catch (Exception)
                    {

                    }
                    try
                    {
                        Response.Write(string.Format("<div class='hoitro_new_title_relate'> <a href='{0}?prid={1}'> {2}</a></div>", Url.Action("Detail", "NewsProduct", new { productTitle = MiscUtil.EscapeString(pNews[1].NProTitle) }), pNews[2].NProId, pNews[2].NProTitle));
                    }
                    catch (Exception)
                    {

                    }
                    try
                    {
                        Response.Write(string.Format("<div class='hoitro_new_title_relate'> <a href='{0}?prid={1}'> {2}</a></div>", Url.Action("Detail", "NewsProduct", new { productTitle = MiscUtil.EscapeString(pNews[1].NProTitle) }), pNews[3].NProId, pNews[3].NProTitle));
                    }
                    catch (Exception)
                    {

                    }
                    if (pNews.Count > 0)
                        Response.Write("</div>");
                    Response.Write("  <div class='hoicho_feature_content'></div>");
                    Response.Write("<div class='clr'></div>");
                }
            }
            else
            {
                Response.Write(string.Format(" <div class='hoicho_group_product'><div class='hoicho_header_feature'><ul><li><p>{0}</p></li></ul></div>", "Tin mới nhất"));
                Response.Write(string.Format("<div>"));
                Response.Write(string.Format("</div></div>"));
        %>
        <div class="private_breakpage" style="text-align: right">
            <%
                int i = 0;
                PageType curPage = (PageType)ViewData["CurrentPage"];
                Category curCate = (Category)ViewData["CurrentCategory"];
                NewsProductHelper.FetchProductResult lstNews = (NewsProductHelper.FetchProductResult)ViewData["NewProducts"];
                int p;
                if (Request.QueryString["p"] != null && int.TryParse(Request.QueryString["p"], out p))
                {
            %>
            <% if (p > 1)
               { %><a href='<%=string.Format("{0}?pid={1}&cid={2}&p={3}'",
                                                     Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                    curPage.PageId,
                                                    Request.QueryString["cid"],
                                                    p-1) %>'><img src="/../Content/Images/arrow_breakpage_left.gif"
                                                        alt="">&nbsp;Trang trước</a>
            <% } %>
            <%
if (p > 3)
    Response.Write(string.Format("<a href='{0}?pid={1}&cid={2}&p={3}' {4}>{5}</a> ",
                                     Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                    curPage.PageId,
                                    Request.QueryString["cid"],
                                    1,
                                    string.Empty,
                                     1));
if (p > 4)
    Response.Write("...");
int total = lstNews.totalPages;
int from = (p - 2 < 1 ? 1 : p - 2);
int to = (p + 2 >= total ? total : p + 2);

for (i = from; i <= to; i++)
    Response.Write(string.Format("<a href='{0}?pid={1}&cid={2}&p={3}' {4}>{5}</a> ",
                                     Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                    curPage.PageId,
                                    Request.QueryString["cid"],
                                    i,
                                    (i == p ? "class='menu_select'" : string.Empty),
                                     i));
if (p <= total - 4)
    Response.Write("...");
if (p <= total - 3)
    Response.Write(string.Format("<a href='{0}?pid={1}&cid={2}&p={3}' {4}>{5}</a> ",
                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                    curPage.PageId,
                                    Request.QueryString["cid"],
                                    total,
                                    string.Empty,
                                    total));
            %>
            <% if (p < lstNews.totalPages)
               { %><a href='<%=string.Format("{0}?pid={1}&cid={2}&p={3}'",
                                                     Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                    curPage.PageId,
                                                    Request.QueryString["cid"],
                                                    p+1) %>'>Trang sau&nbsp;<img src="/../Content/Images/arrow_breakpage_right.gif"
                                                        alt=""></a>
            <% } %>
            <% }  %>
        </div>
        <%
            i = 0;
            //List<NewsProduct> NewestNews = pHelper.getNewestNewsByCate((int.Parse(Request.QueryString.Get("cid"))));
            //foreach (NewsProduct n in NewestNews)
            foreach (NewsProduct n in lstNews.products)
            {
        %>
        <div class="private_thumb_listpr">
            <div class="private_img_post_bt">
                <%
                    string link = string.Format("<a href='{0}?prid={1}'>",
                                        Url.Action("Detail", "NewsProduct", new { productTitle = MiscUtil.EscapeString(n.NProTitle) }),
                                        n.NProId
                                        );
                    
                %>
                <%=link%>
                <img class="private_img_post hoicho_margin_topbottom" src="/../Content/Images/Upload/<%=(n.NewsProductThumbs != null && n.NewsProductThumbs.Count > 0 ? n.NewsProductThumbs.First().NProThumbName : "" )%>"
                    width="140" height="101" /></a></div>
            <div class="private_post_text">
                <p class="private_text_title">
                    <%=link%>
                    <%=n.NProTitle%>
                    </a>
                </p>
                <p class="hoicho_margin_topbottom">
                    <%=n.NProIntro%>
                </p>
                <p class="hoicho_margin_topbottom">
                    <a href="#">
                        <%=n.Member.MemUsername%></a> <span class="hoicho_timer_rate">-
                            <%=n.Province.ProvName%>
                            -
                            <%=n.NProDate.ToString("dd/MM/yyyy hh:mm")%></span></p>
                <div class="private_friend_chat bg_reset">
                    <span class="hoicho_margin_right"><strong>Giá bán:&nbsp;</strong> <span class="private_price">
                        <%=(n.NProPrice == null ? "Thương lượng" : n.NProPrice.Value + " " + n.NProPriceUnit)%></span>
                    </span>
                </div>
                </div>
                </div>
                <%
                    
                    }
            //Response.Write(string.Format("</div></div>"));
                %>
                       <div class="private_breakpage" style="text-align: right">
            <%
                 i = 0;
                 curPage = (PageType)ViewData["CurrentPage"];
                 curCate = (Category)ViewData["CurrentCategory"];
                 lstNews = (NewsProductHelper.FetchProductResult)ViewData["NewProducts"];
                
                if (Request.QueryString["p"] != null && int.TryParse(Request.QueryString["p"], out p))
                {
            %>
            <% if (p > 1)
               { %><a href='<%=string.Format("{0}?pid={1}&cid={2}&p={3}'",
                                                     Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                    curPage.PageId,
                                                    Request.QueryString["cid"],
                                                    p-1) %>'><img src="/../Content/Images/arrow_breakpage_left.gif"
                                                        alt="">&nbsp;Trang trước</a>
            <% } %>
            <%
if (p > 3)
    Response.Write(string.Format("<a href='{0}?pid={1}&cid={2}&p={3}' {4}>{5}</a> ",
                                     Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                    curPage.PageId,
                                    Request.QueryString["cid"],
                                    1,
                                    string.Empty,
                                     1));
if (p > 4)
    Response.Write("...");
int total = lstNews.totalPages;
int from = (p - 2 < 1 ? 1 : p - 2);
int to = (p + 2 >= total ? total : p + 2);

for (i = from; i <= to; i++)
    Response.Write(string.Format("<a href='{0}?pid={1}&cid={2}&p={3}' {4}>{5}</a> ",
                                     Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                    curPage.PageId,
                                    Request.QueryString["cid"],
                                    i,
                                    (i == p ? "class='menu_select'" : string.Empty),
                                     i));
if (p <= total - 4)
    Response.Write("...");
if (p <= total - 3)
    Response.Write(string.Format("<a href='{0}?pid={1}&cid={2}&p={3}' {4}>{5}</a> ",
                                    Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                    curPage.PageId,
                                    Request.QueryString["cid"],
                                    total,
                                    string.Empty,
                                    total));
            %>
            <% if (p < lstNews.totalPages)
               { %><a href='<%=string.Format("{0}?pid={1}&cid={2}&p={3}'",
                                                     Url.Action("Page", "Home", new { pageName = MiscUtil.EscapeString(curPage.PageName) }),
                                                    curPage.PageId,
                                                    Request.QueryString["cid"],
                                                    p+1) %>'>Trang sau&nbsp;<img src="/../Content/Images/arrow_breakpage_right.gif"
                                                        alt=""></a>
            <% } %>
            <% }  %>
        </div>
                <%
                
                }
                %>
                <%}
          else
          { %>
                <%--cuc 2--%>
                <div class="private_breakpage" style="text-align: right">
                    <%
                int i = 0;
                PageType curPage = (PageType)ViewData["CurrentPage"];
                Category curCate = (Category)ViewData["CurrentCategory"];
                NewsProductHelper.FetchProductResult lstNews = (NewsProductHelper.FetchProductResult)ViewData["NewProducts"];
                int p;
                if (Request.QueryString["p"] != null && int.TryParse(Request.QueryString["p"], out p))
                {
                    %>
                    <% if (p > 1)
                       { %><a href='<%=string.Format("{0}?pid={1}&cid={2}&p={3}&date={4}'",
                                                    "/Home/SearchNews/",
                                                    curPage.PageId,
                                                    Request.QueryString["cid"],
                                                    p-1,Request.QueryString["date"]) %>'><img src="/../Content/Images/arrow_breakpage_left.gif"
                                                        alt="">&nbsp;Trang trước</a>
                    <% } %>
                    <%
                if (p > 3)
                    Response.Write(string.Format("<a href='{0}?pid={1}&cid={2}&p={3}&date={6}' {4}>{5}</a> ",
                                                    "/Home/SearchNews/",
                                                    curPage.PageId,
                                                    Request.QueryString["cid"],
                                                    1,
                                                    string.Empty,
                                                     1, Request.QueryString["date"]));
                if (p > 4)
                    Response.Write("...");
                int total = lstNews.totalPages;
                int from = (p - 2 < 1 ? 1 : p - 2);
                int to = (p + 2 >= total ? total : p + 2);

                for (i = from; i <= to; i++)
                    Response.Write(string.Format("<a href='{0}?pid={1}&cid={2}&p={3}&date={6}' {4}>{5}</a> ",
                                                    "/Home/SearchNews/",
                                                    curPage.PageId,
                                                    Request.QueryString["cid"],
                                                    i,
                                                    (i == p ? "class='menu_select'" : string.Empty),
                                                     i, Request.QueryString["date"]));
                if (p <= total - 4)
                    Response.Write("...");
                if (p <= total - 3)
                    Response.Write(string.Format("<a href='{0}?pid={1}&cid={2}&p={3}&date={6}' {4}>{5}</a> ",
                                                   "/Home/SearchNews/",
                                                    curPage.PageId,
                                                    Request.QueryString["cid"],
                                                    total,
                                                    string.Empty,
                                                    total, Request.QueryString["date"]));
                    %>
                    <% if (p < lstNews.totalPages)
                       { %><a href='<%=string.Format("{0}?pid={1}&cid={2}&p={3}&date={4}'",
                                                    "/Home/SearchNews/",
                                                    curPage.PageId,
                                                    Request.QueryString["cid"],
                                                    p+1,Request.QueryString["date"]) %>'>Trang sau&nbsp;<img src="/../Content/Images/arrow_breakpage_right.gif"
                                                        alt=""></a>
                    <% } %>
                    <% }  %>
                </div>
                <%
                i = 0;
                foreach (NewsProduct n in lstNews.products)
                {
                %>
                <div class="private_thumb_listpr">
                    <div class="private_img_post_bt">
                        <%--<a href="<%=Url.Action("Detail", "NewsProduct", new {newsId=n.NProId})%>">--%>
                        <% string link = string.Format("<a href='{0}?prid={1}'>",
                                            Url.Action("Detail", "NewsProduct", new { productTitle = MiscUtil.EscapeString(n.NProTitle) }),
                                            n.NProId
                                            );
                        %>
                        <%=link%>
                        <img class="private_img_post hoicho_margin_topbottom" src="/../Content/Images/Upload/<%=(n.NewsProductThumbs != null && n.NewsProductThumbs.Count > 0 ? n.NewsProductThumbs.First().NProThumbName : "" )%>"
                            width="140" height="101" /></a></div>
                    <div class="private_post_text">
                        <p class="private_text_title">
                            <%=link%>
                            <%=n.NProTitle%>
                            </a>
                        </p>
                        <p class="hoicho_margin_topbottom">
                            <%=n.NProIntro%>
                        </p>
                        <p class="hoicho_margin_topbottom">
                            <a href="#">
                                <%=n.Member.MemUsername%></a> <span class="hoicho_timer_rate">-
                                    <%=n.Province.ProvName%>
                                    -
                                    <%=n.NProDate.ToString("dd/MM/yyyy hh:mm")%></span></p>
                        <div class="private_friend_chat bg_reset">
                            <span class="hoicho_margin_right"><strong>Giá bán:&nbsp;</strong> <span class="private_price">
                                <%=(n.NProPrice == null ? "Thương lượng" : n.NProPrice.Value + " " + n.NProPriceUnit)%></span>
                            </span>
                        </div>
                    </div>
                    <div class="hoicho_list_reviews">
                        <div>
                            <input type="submit" style="#width: 100px;" id="Submit1" value="Đánh giá" class="private_bt_submit_news_disable">
                        </div>
                        <div>
                            <a href="#" class="hoicho_margin_topbottom">
                                <img alt="" src="/../Content/Images/button_member.gif"></a></div>
                    </div>
                </div>
                <!-- End thumb list sp -->
                <%
                }
                %>
                <div class="private_breakpage" style="text-align: right">
                    <%
                i = 0;
                curPage = (PageType)ViewData["CurrentPage"];
                curCate = (Category)ViewData["CurrentCategory"];
                lstNews = (NewsProductHelper.FetchProductResult)ViewData["NewProducts"];

                if (Request.QueryString["p"] != null && int.TryParse(Request.QueryString["p"], out p))
                {
                    %>
                    <% if (p > 1)
                       { %><a href='<%=string.Format("{0}?pid={1}&cid={2}&p={3}&date={4}'",
                                                    "/Home/SearchNews/",
                                                    curPage.PageId,
                                                    Request.QueryString["cid"],
                                                    p-1,Request.QueryString["date"]) %>'><img src="/../Content/Images/arrow_breakpage_left.gif"
                                                        alt="">&nbsp;Trang trước</a>
                    <% } %>
                    <%
                if (p > 3)
                    Response.Write(string.Format("<a href='{0}?pid={1}&cid={2}&p={3}&date={6}' {4}>{5}</a> ",
                                                    "/Home/SearchNews/",
                                                    curPage.PageId,
                                                    Request.QueryString["cid"],
                                                    1,
                                                    string.Empty,
                                                     1, Request.QueryString["date"]));
                if (p > 4)
                    Response.Write("...");
                int total = lstNews.totalPages;
                int from = (p - 2 < 1 ? 1 : p - 2);
                int to = (p + 2 >= total ? total : p + 2);

                for (i = from; i <= to; i++)
                    Response.Write(string.Format("<a href='{0}?pid={1}&cid={2}&p={3}&date={6}' {4}>{5}</a> ",
                                                    "/Home/SearchNews/",
                                                    curPage.PageId,
                                                    Request.QueryString["cid"],
                                                    i,
                                                    (i == p ? "class='menu_select'" : string.Empty),
                                                     i, Request.QueryString["date"]));
                if (p <= total - 4)
                    Response.Write("...");
                if (p <= total - 3)
                    Response.Write(string.Format("<a href='{0}?pid={1}&cid={2}&p={3}&date={6}' {4}>{5}</a> ",
                                                   "/Home/SearchNews/",
                                                    curPage.PageId,
                                                    Request.QueryString["cid"],
                                                    total,
                                                    string.Empty,
                                                    total, Request.QueryString["date"]));
                    %>
                    <% if (p < lstNews.totalPages)
                       { %><a href='<%=string.Format("{0}?pid={1}&cid={2}&p={3}&date={4}'",
                                                    "/Home/SearchNews/",
                                                    curPage.PageId,
                                                    Request.QueryString["cid"],
                                                    p+1,Request.QueryString["date"]) %>'>Trang sau&nbsp;<img src="/../Content/Images/arrow_breakpage_right.gif"
                                                        alt=""></a>
                    <% } %>
                    <% }  %>
                </div>
                <%} %>
                <%--end cuc 2--%>
            </div>
          
            <div class="right">
                <div style="height:40px;background-color:#eef2f5">
                 <%--   <div class="hoicho_header_feature">--%>
                        <ul>
                            <li>
                                <p style="font-size:14px;font-weight:bold;padding:10px;">
                                    Tâm điểm</p>
                            </li>
                        </ul>
                  <%--  </div>--%>
                </div>
                <%
                    List<NewsProduct> poNews = pHelper.getPopularNews();
                    foreach (NewsProduct pop in poNews)
                    {
                        %>
                        <div class="hoitro_new_popular">
                        <div style="float:left;width:3%">
                        <img src='../Content/Images/new_point_start.jpg' style='margin:10px 3px;'/>
                        </div>
                        <div style="float:right;width:97%">
                            <%
                        Response.Write(string.Format("<a href='{0}?prid={1}'>{2}</a>", Url.Action("Detail", "NewsProduct", new { productTitle = MiscUtil.EscapeString(pop.NProTitle) }), pop.NProId, pop.NProTitle));
                        %>
                        </div>
                        <div class="clr"></div>
                        </div>
                        <%
                    }
                %>
                <div class="hoicho_topbanner">
                    <%
                        Response.Write(hAdvert.showBanner(ViewData, 7));
                    %>
                </div>
            </div>
            <div class="clr">
            </div>
            <%--end content--%>
</asp:Content>
